/*
 * @Date: 2023-08-30 17:26:20
 * @LastEditTime: 2023-08-30 17:26:22
 * @Description: 
 */

#define SERIAL_ADDR 0xfcc9
#define FIRMWARE_ADDR 0x84b8
#define TMP_ADDR 0xe3
#define HUM_ADDR 0xe5
#define GET_SERIAL _IOR('g',0,int)
#define GET_FIRMWARE _IOR('g',1,int)
#define GET_TMP _IOR('g',2,int)
#define GET_HUM _IOR('g',3,int)
// #include "si7006.h"
#include <head.h>
#include <sys/ioctl.h>
int main(int argc, const char* argv[])
{
    int fd;
    int serial, firmware, tmp, hum;
    float rtmp, rhum;
    if ((fd = open("/dev/si7006", O_RDWR)) == -1)
        PRINT_ERR("open error");

    ioctl(fd, GET_SERIAL, &serial);
    ioctl(fd, GET_FIRMWARE, &firmware);
    printf("serial = %#x,firmware=%#x\n", serial, firmware);
    while (1) {
        ioctl(fd, GET_TMP, &tmp);
        ioctl(fd, GET_HUM, &hum);

        rtmp = 175.72 * tmp / 65536 - 46.85;
        rhum = 125 * hum / 65536.0 - 6;

        printf("rtmp = %.2f,rhum = %.2f\n",rtmp,rhum);
        usleep(100000);
    }
    close(fd);
    return 0;
}